#include "form2.h"
#include "ui_form2.h"

#include <QToolBox>
#include <QVBoxLayout>
#include <QToolButton>
#include <QGroupBox>


int TaskTarget_number;
int Task_flag; //0任务目标，

Form2::Form2(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form2)
{
    ui->setupUi(this);
    initMenu(); //初始化菜单

    TaskTarget_number=3;
}

Form2::~Form2()
{
    delete ui;
}

//左键弹出菜单
void Form2::on_pushButton_3_clicked()
{
    Task_flag=0;
    menu->exec(QCursor::pos());

}


// ///////////////////添加任务目标选项（这里还需要具体考虑不同目标的属性框）
void Form2::Add_TaskTarget()
{
    QWidget *pGroup1 = new QWidget;
//    pGroup2->resize(140, 70); // 设置窗口宽度\高度

    QFormLayout* layout = new QFormLayout();

    //第二列的输入框架
    QComboBox *comboBox1 = new QComboBox; //comboBox
    comboBox1->addItem("静态目标-点目标");
    comboBox1->addItem("型号2");

    // 第二列的空白输入框
    QLineEdit* text1 = new QLineEdit();
    QLineEdit* text2 = new QLineEdit();
    QLineEdit* text3 = new QLineEdit();
    QLineEdit* text4 = new QLineEdit();
    QLineEdit* text5 = new QLineEdit();

    layout->addRow("目标类型",comboBox1);
    layout->addRow("目标坐标",text1);
    layout->addRow("目标速度",text2);
    layout->addRow("目标移动轨迹",text3);
    layout->addRow("目标移动范围",text4);
    layout->addRow("目标出现时间段",text5);


    //对齐方式
    layout->setRowWrapPolicy(QFormLayout::DontWrapRows); //保持一行

    //调整间隙
    layout->setSpacing(5);
    setLayout(layout);
    pGroup1->setLayout(layout);


    //名字递增
    TaskTarget_number = TaskTarget_number+1;
    QString str = QString("任务目标%1").arg(TaskTarget_number);

    QPushButton *button_new2 = new QPushButton();
    button_new2->setText(str);
    ui->toolBox_2->addItem(pGroup1, str);
    ui->toolBox_2->setCurrentIndex(TaskTarget_number);     //设置当前选项卡下标

    // toolBox1的长度、scrollAreaWidgetContents_3的长度要增加
    ui->scrollAreaWidgetContents->setFixedHeight(ui->scrollAreaWidgetContents->height()+35); //设置滚动轴的有效区域
    ui->toolBox_2->setFixedHeight(ui->toolBox_2->height()+35);
}

//删除任务目标选项
void Form2::Delete_TaskTarget()
{
    TaskTarget_number = TaskTarget_number-1;
    qDebug()<< ui->toolBox_2->count();  //获取选项卡数
    ui->toolBox_2->removeItem(TaskTarget_number); //删除最下面的item
    ui->scrollAreaWidgetContents->setFixedHeight(ui->scrollAreaWidgetContents->height()-35); //设置滚动轴的有效区域
    ui->toolBox_2->setFixedHeight(ui->toolBox_2->height()-35);

}

//重写mousePressEvent单击事件
void Form2::mousePressEvent(QMouseEvent *event)
{
    switch (event->button()) {
    case Qt::LeftButton:
        emit clicked(); //发送左键单击信号
        break;

    case Qt::RightButton:
        emit clicked_right(); //发送右键单击信号
        break;

    default:break;  //否则有警告28...
    }

    //将该事件传给父类处理
    QWidget::mousePressEvent(event);
}



//初始化菜单
void Form2::initMenu(){
    setContextMenuPolicy(Qt::ActionsContextMenu);
    /* 创建右键菜单 */
    QAction *test_menu1 = new QAction("增加",this); //添加测试功能菜单
    QAction *test_menu2 = new QAction("删除",this);
    QAction *test_menu3 = new QAction("编辑",this);
    QAction *test_menu4 = new QAction("查找",this);

    /* 添加菜单项 */
    menu->addAction(test_menu1);
    menu->addAction(test_menu2);
    menu->addAction(test_menu3);
    menu->addAction(test_menu4);


    /* 连接槽函数 */
    connect(test_menu1,SIGNAL(triggered()),this,SLOT(menu_slot1())); //连接 测试 功能
    connect(test_menu2,SIGNAL(triggered()),this,SLOT(menu_slot2())); //

}


// 菜单栏的每一个按钮的槽函数
//菜单的增加功能
void Form2::menu_slot1(){
    //这里写入功能实现代码
    switch(Task_flag)
    {
    case 0:Add_TaskTarget();
    default:break;
    }
}
//菜单的删除功能
void Form2::menu_slot2(){
    switch(Task_flag)
    {
    case 0:Delete_TaskTarget();
    default:break;
    }
}

// 开始分析按钮
void Form2::on_pushButton_clicked()
{
    //25目标分析、26气象分析、31地形分析、32威胁分析、27装备分析
    ui->label_25->setText("正在目标分析...");
    ui->label_26->setText("正在气象分析...");
    ui->label_31->setText("正在地形分析...");
    ui->label_32->setText("正在威胁分析...");
    ui->label_27->setText("正在装备分析...");

}

//结束分析按钮
void Form2::on_pushButton_2_clicked()
{
    ui->label_25->setText("目标分析结束，合理");
    ui->label_26->setText("气象正常");
    ui->label_31->setText("地形为平原");
    ui->label_32->setText("威胁指数低");
    ui->label_27->setText("装备正常");
}

